
package com.yyj.result;

/**
 * 结果工具类，方便生成一些公共，常用的结果实例
 * 
 */
public abstract class Results {

    /** 成功结果 */
    public static <T> Result<T> success(String message) {
        return success(null, message);
    }
    /** 成功结果 */
    public static <T> Result<T> success(T data) {
        return success(data, ResultEnum.SUCCESS.getMessage());
    }

    /** 成功结果 */
    public static <T> Result<T> success(T data, String msg) {
        return newResult(data, ResultEnum.SUCCESS.getCode(), msg);
    }

    /** 没有数据回传的失败结果 */
    public static <T> Result<T> fail(ResultEnum resultEnum) {
        return fail(null, resultEnum);
    }

    /** 没有数据回传的失败结果 */
    public static <T> Result<T> fail(ResultEnum resultEnum, String msg) {
        return fail(null, resultEnum.getCode(), msg);
    }

    /** 有数据回传的失败结果 */
    public static <T> Result<T> fail(T data, ResultEnum resultEnum) {
        return fail(data, resultEnum.getCode(), resultEnum.getMessage());
    }

    /** 有数据回传的失败结果 */
    public static <T> Result<T> fail(T data, String code, String msg) {
//        CheckIsNullOrEmptyUtil.isNullOrEmpty(resultEnum);
//        checkArgument(failedCode.getCode() < 0,
//            "invalid code, for failed result, code must be negative integers");
        return newResult(data, code, msg);
    }
    
    /** 仅返回状态码*/
    public static <T> Result<T> newResult(ResultEnum resultEnum) {
        return newResult(null, resultEnum.getCode(), resultEnum.getMessage());
    }

    /** 有数据回传的结果 */
    public static <T> Result<T> newResult(T data, String code, String msg) {
        Result<T> result = new Result<T>();
        result.setData(data);
        result.setCode(code);
        result.setMsg(msg);
        return result;
    }
}
